/*
 * @lc app=leetcode.cn id=841 lang=typescript
 *
 * [841] 钥匙和房间
 */

// @lc code=start
function canVisitAllRooms(rooms: number[][]): boolean {
    let set = new Set();
    set.add(0)
    const n = rooms.length;
    const queue: any = [0];
    while (queue.length !== 0) {
        const index = queue.shift();
        for (let i = 0; i < rooms[index].length; i++) {
            if (set.has(rooms[index][i])) {
                continue
            }
            set.add(rooms[index][i]);
            queue.push(rooms[index][i])
        }
    }
    return set.size === n;
};
// @lc code=end

